package com.example.threaddemo.reference;

import java.lang.ref.WeakReference;

public class WeakRefDemo {
    public static void main(String[] args) {
        Object o1 = new Object();

        WeakReference<Object> weakReference = new WeakReference<>(o1);

        System.out.println(o1);
        System.out.println(weakReference.get());
        System.out.println("GC后-----------------");
        o1 = null;
        System.gc();
        System.out.println(o1);
        System.out.println(weakReference.get());
    }
}
